package com.exercise.DesignPattern.CreationalPatterns.PrototypePattern;

//原型实体类
public class ConcretePrototype implements Prototype {

    private String data;

    public ConcretePrototype(String data) {
        this.data = data;
    }

    //浅拷贝
    @Override
    public Prototype clone() {
        try {
            return (Prototype) super.clone();
        } catch (CloneNotSupportedException e) {
            // 处理克隆不支持异常
            return null;
        }
    }

    public void setData(String data) {
        this.data = data;
    }
    public String getData(){
        return data;
    }

}
//客户端代码
class Client {

    public static void main(String[] args) {

        ConcretePrototype dao = new ConcretePrototype("倒霉");
        ConcretePrototype clone = (ConcretePrototype)dao.clone();

    }
}
